/**
 * 
 */
gaugeThs = new Object();// 表头
gaugeThs["gaugeRemainingDays"] = 123456;
$(function() {
	$(".gaugeNav").click(function() {
		addTab();
	});
	
	//$("#logout").click(logout);
	// 收缩侧边栏
	$("#nav-bottom").click(function() {

		var width = $("#side-left").css("width");
		if (width == "180px") {
			$("#side-left").animate({
				width : "60px"
			})
			$("#nav-bottom span").attr("class", "glyphicon glyphicon-chevron-right");
			$(".nav-options").addClass("nav-closed");
			$(".nav-text").hide();
			$("#side-right").animate({
				left : "60px"
			});
			$("#header").animate({
				left : "60px"
			});
		} else {
			$("#side-left").animate({
				width : "180px"
			})
			$("#nav-bottom span").attr("class", "glyphicon glyphicon-chevron-left");
			$(".nav-text").show();
			$(".nav-options").removeClass("nav-closed");
			$("#side-right").animate({
				left : "180px"
			});
			$("#header").animate({
				left : "180px"
			});
		}
	})

	// 左边侧边栏导航

	$(".nav-options").hover(function() {
		var width = $("#side-left").css("width");
		var top = $(this).offset().top;
		if (width == "60px") {
			var tip = "<div class='nav-tip'><div class='nav-tip-text'>" + $(this).attr("tip") 
			+ "</div><div class='arrow'></div></div>"
			$("body").append(tip);
			var newTip = $(".nav-tip");
			newTip.css({
				"position" : "absolute",
				"top" : (top + 9) + "px",
				"left" : "120px"
			});
			if (!(newTip.is(":animated"))) {
				newTip.animate({
					"left" : "70px"
				}, "fast");

			}

		}

	}, function() {

		$(".nav-tip").remove();

	});

	// 顶部导航hover

	$(".top-nav").hover(function() {

		$(this).addClass("white-bg");
		var id = "#" + $(this).attr("id") + "-box";
		$(id).stop();
		$(id).slideDown();
	}, function() {
		$(this).removeClass("white-bg");
		var id = "#" + $(this).attr("id") + "-box";
		$(id).stop();
		$(id).slideUp();
	})

	$(".li-box").hover(function() {
		$(this).stop();
		$(this).slideDown();
	}, function() {
		$(this).stop();
		$(this).slideUp();
	});

	$(".nav-options").click(openTab);

})


function logout(){
	$.post("logout.do",function(){
		location.href="login.html";
	});
}

function openTab() {
	var id = $(this).attr("id");
	for ( var key in gaugeThs) {
		delete gaugeThs[key];
	}
	gaugeThs["gaugeRemainingDays"] = 123456;
	if (id == "needToCalibrateThisMonth") {
		var date = new Date();
		var m = date.getMonth() + 1;
		var y = date.getFullYear();
		date = new Date(y, m, "0");
		var m = date.getMonth() + 1;
		var y = date.getFullYear();
		m = m < 10 ? "0" + m : m;
		var d = date.getDate();
		var lastDate = y + "-" + m + "-" + d;
		gaugeThs["dateOfNextCalibration_end"] = lastDate;
		gaugeThs["dateOfNextCalibration"] = "to" + lastDate;
	}
	if (id == "expired") {
		var date = new Date();
		var m = date.getMonth() + 1;
		m = m < 10 ? "0" + m : m;
		var y = date.getFullYear();
		var d = date.getDate();
		var today = y + "-" + m + "-" + d;
		gaugeThs["dateOfNextCalibration"] = "to" + today;
	}
	if (id == "lost") {
		gaugeThs["gaugeStatus"] = "已丢失";
	}
	if (id == "scrapped") {
		gaugeThs["gaugeStatus"] = "已报废";
	}
	if (id == "userCenter") {
		$("#body-iframe").attr("src", "userCenter.html");
		return;
	}
	if (id == "userManager") {
		$("#body-iframe").attr("src", "userManager.html");
		return;
	}
	if (id == "overview") {
		$("#body-iframe").attr("src", "overview.html");
		return;
	}
	$("#body-iframe").attr("src", "allGauges.html");
}